# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=dcc
pkgver=2.3.169
pkgrel=1
pkgdesc="Distributed Checksum Clearinghouses or DCC spam filter"
url="https://www.dcc-servers.net/dcc/"
arch="all"
license="custom"
pkgusers="dcc"
pkggroups="dcc"
makedepends="libmd-dev libmilter-dev"
subpackages="$pkgname-dccd $pkgname-dccifd $pkgname-dccm
	$pkgname-extras $pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://www.dcc-servers.net/src/dcc/old/dcc-$pkgver.tar.Z
	10-$pkgname-alpine.patch
	20-$pkgname-config.patch
	30-pid.patch
	dccd.initd
	dccd-grey.initd
	dccifd.initd
	dccm.initd
	"
install="$pkgname.pre-install $pkgname.post-install $pkgname.post-deinstall"
# there is no test suite
options="!check"

prepare() {
	chmod 755 configure
	chmod 644 include/dcc_types.h include/dcc_config.h.in homedir/dcc_conf.in LICENSE
	default_prepare
}

build() {
	./configure \
		--with-installroot="$pkgdir" \
		--bindir="/usr/bin" \
		--mandir="/usr/share/man" \
		--libexecdir="/usr/libexec" \
		--with-cgi-bin="/usr/lib/dcc/cgi-bin" \
		--with-uid=dcc
	make
}

package() {
	make install

	cd "$pkgdir"
	install -Dm 755 "$srcdir"/dccd.initd "$pkgdir"/etc/init.d/dccd
	install -Dm 755 "$srcdir"/dccd-grey.initd "$pkgdir"/etc/init.d/dccd-grey
	install -Dm 755 "$srcdir"/dccm.initd "$pkgdir"/etc/init.d/dccm
	install -Dm 755 "$srcdir"/dccifd.initd "$pkgdir"/etc/init.d/dccifd

	install -Dm644 "$builddir"/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	chmod 755 "$pkgdir/usr/libexec/dccsight"
	cd "$pkgdir"/usr/bin
	chmod 755 cdcc dccproc
}

dccd() {
	pkgdesc="$pkgdesc (dccd server with grey listing)"
	depends="dcc"

	amove \
		usr/libexec/dccd \
		usr/libexec/start-dccd \
		usr/libexec/stop-dccd \
		usr/libexec/start-grey \
		usr/libexec/dump-clients \
		usr/libexec/dblist \
		usr/libexec/dccsight
}

dccifd() {
	pkgdesc="$pkgdesc (dccifd server)"
	depends="dcc"

	amove \
		usr/libexec/dccifd \
		usr/libexec/start-dccifd
}

dccm() {
	pkgdesc="$pkgdesc (dccm server)"
	depends="dcc"

	amove \
		usr/libexec/dccm \
		usr/libexec/start-dccm
}

extras() {
	pkgdesc="$pkgdesc (dcc user commands)"
	depends="dcc"

	amove \
		usr/libexec/updatedcc \
		usr/libexec/uninstalldcc \
		usr/libexec/rcDCC
	amove \
		usr/bin/dccproc \
		usr/bin/dccif-test
}

sha512sums="
bf8b7f1ac582c5b76879983be17b436eb26029f2bc744ce5c22f45e140050966d3c11bcce819622bbf349a53e23855193e91f1dff07bd6337a8a04afa9e1be07  dcc-2.3.169.tar.gz
8efe22be50da74abdf8fe26de028f13d7ee572c0f1fcfb174bcd8083523c0c5d2b0a5c2580d77d031c23f5ce728e045a6ba8ef9069a19cc6bcfe865142849d41  10-dcc-alpine.patch
8f7455cb8d49f26688fb8110c1a75311d9a8365e384dedbad7ab48bccdce6c0114f0c22d2024d05ab31d7ae5cdacf96972d8a7c0c361b767bde6532e1d9a94c7  20-dcc-config.patch
3a5d0b2cba23a6522fc068d225d3fd1abb68e9494802869e45533d5a9c2aaddf45f75aafbfb98bfb502e44c25c0befc569e20ef2d1884356a608012c73caf45f  30-pid.patch
31bf9d04664e4a66d432131852a3a89f4a558dba3f7b043961d7521a5dc23abd47cf8d110af2a0b9895199e280a9a9d8b1960a32699f09634e9007b1ba5330b7  dccd.initd
3788f5aba6fd3f63501394e3ac291d188534370dce2611d69f44f3523aa33dd488bd82b161f9e9b1346c1889dfb674408d0029b09db557fae3812983ae3d7359  dccd-grey.initd
8090feaabc68756aa79bb5210b27ef6927c7336c474c01cb59e67735c11fc9cfaa1a932c554edd33209889198bf6695cf73a20f6e184556b956884550eddf483  dccifd.initd
d6fee7aa2a0b82d7a2a5858cf0dcf780825e120a5a4c6ad45ef35f5deb69f60d9cdd2da4239e49749842f940c9db7ccf6054440f0d9fe4aa5497ec5ebddfd8ea  dccm.initd
"
